package com.binfast.bean.model.auth;

import com.binfast.seed.base.BaseModel;
import lombok.Data;
import org.beetl.sql.core.annotatoin.Table;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/* 
* 
* gen by beetlsql 2018-09-12
*/
@Data
@Table(name="admin_menu")
public class AdminMenu  extends BaseModel {
	
	/*
	当前生成的code数
	*/
	private Integer codeNum ;
	/*
	是否初始化
	*/
	private Integer isInit ;
	/*
	是否展示该业务 0：是；1否
	*/
//	private Boolean isHidden ;
	private Integer level ;
	private String code ;
	private String parentCode;
	/*
	生成code日期
	*/
	private String codeDate ;
//	private String redirect ;
//	private String iconCls ;
	private Integer isLeaf;
	private String name ;
	private String prefix ;
	private String remark ;
	private Long showOrder ;
//	private String path ;
	private String pageName ;
//	private String component ;
//	private String title ;
//	private Boolean noCache ;

	private List<AdminMenu> menuList;

	public static List<AdminMenu> generateTreeMenu(List<AdminMenu> menuList) {
		List<AdminMenu> adminMenuList = new ArrayList<>();
		Map<String,AdminMenu> map = new HashMap<>();
		for(AdminMenu menu :menuList ){
			if(menu.getLevel()  != 3){
				map.put(menu.getCode(),menu);
			}
			if(map.get(menu.getParentCode()) != null){
				AdminMenu parent =  map.get(menu.getParentCode());
				List<AdminMenu> menus = parent.getMenuList();
				if(menus == null) menus = new ArrayList<>();
				menus.add(menu);
				parent.setMenuList(menus);
			}else {
				adminMenuList.add(menu);
			}
		};
		return adminMenuList;
	}
}
